package com.kmproject.haifu.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.TimeUtils;
import com.kmproject.haifu.mvp.model.entity.beans.SecondHandInfoBean;

import java.util.List;

public class SenondHandObtainedItemAdapter extends BaseQuickAdapter<SecondHandInfoBean, BaseViewHolder> {
    ImageLoader glideImage;

    public SenondHandObtainedItemAdapter( @Nullable List<SecondHandInfoBean> data) {
        super(R.layout.secondhand_obt_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SecondHandInfoBean item) {
        if (glideImage == null) {
            glideImage = ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
        helper.<TextView>getView(R.id.secondhand_obt_item_title).setText(item.getLowerShelfReasonName());
        if (item.getImages()!=null&&!item.getImages().isEmpty())
        {
            glideImage.loadImage(mContext, ImageConfigImpl.builder().url(item.getImages().get(0).getImageUrl())
                    .imageView(helper.<ImageView>getView(R.id.houserenting_main_content_item_img))
                    .build());
        }
        if (Integer.parseInt(item.getCreateTime().substring(0,4)) < Integer.parseInt(TimeUtils.getYear().length()>4?TimeUtils.getYear().substring(0,4):TimeUtils.getYear()))
        {
            helper.<LinearLayout>getView(R.id.secondhand_obt_item_del).setVisibility(View.VISIBLE);
        }else {
            helper.<LinearLayout>getView(R.id.secondhand_obt_item_del).setVisibility(View.INVISIBLE);
        }
        helper.addOnClickListener(R.id.secondhand_obt_item_del);
            helper.<TextView>getView(R.id.secondhand_obt_item_name).setText(item.getTitle());

        helper.<TextView>getView(R.id.secondhand_obt_item_content).setText(item.getViewCount()+"次浏览，"+item.getCollectionCount()+"人想要");
        helper.<TextView>getView(R.id.secondhand_obt_item_price).setText(item.getSalePrice()+"P");

    }
}
